/**
 * Created by Administrator on 2015/7/27.
 */
$(function(){

    /********************************全部订单********************************************************/
    /* 切换页面 */
    $('.scy-function').on(status,'.scy-search',function(event){
        $('.newleft').addClass('new-in');
        $('.newright').addClass('new-on');
        $('.new-hidden').height($('.newright').height());
        event.stopPropagation();
    });
    $('.all-order-ly').on(status,'.page2-return',function(event){
        $('.newleft').removeClass('new-in');
        $('.newright').removeClass('new-on');
        $('.new-hidden').height('100%');
        event.stopPropagation();
    });

    $('#order-refund-images').change(function(){
        $(this).next().find('span').text($(this).val());
    });

    //退款申请验证
    $('#order-refund-apply').validate({
        submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form
            $('#order-refund-apply').find('button[type=submit]').attr('disabled', 'disabled');
            $('#order-refund-apply').find('button[type=submit]').html('正在提交...');
            form.submit();   //提交表单
        },
        rules:{
            number:{
                required:true
            },
            cellphone:{
                required:true,
                mobile:true
            },
            user_name:{
                required:true,
                rangelength:[2,15]
            },
            refund_content:{
                required:true,
                rangelength:[1,50]
            }
        },
        messages:{
            number:{
                required:"请选择退货数量"
            },
            cellphone:{
                required:'请输入手机号码',
                mobile:'手机号码格式不正确'
            },
            user_name:{
                required:'请输入联系人姓名',
                rangelength:'联系人姓名长度需在2到15位以内'
            },
            refund_content:{
                refund_content:'请输入退款说明',
                rangelength:'退款说明长度需在6到50位以内'
            }
        }
    });

    //取消订单
    $('#wrapper').on(status, '.order-cancel', function(){
        var id = $(this).attr('data-id');
        var nconfirm = layer.open({
            type: 1, //1代表页面层
            content: '<div class="content"><div class="title">确定要取消订单吗？</div></div><div class="con-body am-cf"><a class="am-btn closediy">取消</a><a class="am-btn closediy">确定</a></div>',
            style: 'min-width:12rem;max-width:15rem;padding:0.5rem;border-radius:0.25rem',
            shadeClose:false,
            success: function(olayer){
                var cla = 'getElementsByClassName';
                olayer[cla]('closediy')[0].onclick = function(){
                    layer.close(nconfirm)
                }
                olayer[cla]('closediy')[1].onclick = function(){
                    layer.close(nconfirm);
                    window.location.href = hostUrl()+'user/cancelOrder/' + id;
                }
            }
        });
    });

    //确认订单
    $('#wrapper').on(status, '.order-enter', function(){
        var id = $(this).attr('data-id');
        var nconfirm = layer.open({
            type: 1, //1代表页面层
            content: '<div class="content"><div class="title">确定要收货吗？</div></div><div class="con-body am-cf"><a class="am-btn closediy">取消</a><a class="am-btn closediy">确定</a></div>',
            style: 'max-width:12em;padding:0.5em;border-radius:0.25em',
            shadeClose:false,
            success: function(olayer){
                var cla = 'getElementsByClassName';
                olayer[cla]('closediy')[0].onclick = function(){
                    layer.close(nconfirm)
                }
                olayer[cla]('closediy')[1].onclick = function(){
                    layer.close(nconfirm);
                    window.location.href = hostUrl()+'user/confirmReceipt/' + id;
                }
            }
        });
    });

    //清除订单cookie
    $('.page2-isory').on(status, '.order-history-clear', function(){
        //$('.page2-isory').find('li.hidth').remove();
        $.ajax({
            type:'post',
            async:false,
            url:hostUrl() + 'user/deleteCookie',
            data:{},
            dataType:'json',
            success:function(json){
                $('.page2-isory').find('li.hidth').remove();
            }
        });
    });
});